﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.t106Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void t106_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            t106Mgr mgr = new t106Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_t106(e.Parameters[t106_Filter.ParamPrefix]));
            IList<t106> list = mgr.FindAllByPage_t106(e.Start.ToString(), e.Limit.ToString(), e.Parameters[t106_Filter.ParamPrefix]);
            t106_MainStore.DataSource = list;
            t106_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            t106Mgr mgr = new t106Mgr();
            RowSelectionModel sm = t106_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                t106 _t106 = new t106();
                _t106.t106_00 = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_t106(_t106))
                {
                    log.Debug("t106中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            t106_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            t106Mgr mgr = new t106Mgr();
            t106 _t106 = new t106();
            if (Hid.Text.Length > 0)
                _t106 = mgr.FindById_t106(int.Parse(Hid.Text));
            
			_t106.t106_01 = Txtt106_01.Text.Trim();
			_t106.t106_02 = Txtt106_02.Text.Trim();
			_t106.t106_03 = Txtt106_03.Text.Trim();
			_t106.t106_04 = Txtt106_04.Text.Trim();
			_t106.t106_70 = Txtt106_70.Text.Trim();
			_t106.t106_05 = Txtt106_05.Text.Trim();
			_t106.t106_71 = Txtt106_71.Text.Trim();
			_t106.t106_06 = Txtt106_06.Text.Trim();
			_t106.t106_72 = Txtt106_72.Text.Trim();
			_t106.t106_07 = Txtt106_07.Text.Trim();
			_t106.t106_73 = Txtt106_73.Text.Trim();
			_t106.t106_08 = Txtt106_08.Text.Trim();
			_t106.t106_74 = Txtt106_74.Text.Trim();
			_t106.t106_09 = Txtt106_09.Text.Trim();
			_t106.t106_75 = Txtt106_75.Text.Trim();
			_t106.t106_10 = Txtt106_10.Text.Trim();
			_t106.t106_76 = Txtt106_76.Text.Trim();
			_t106.t106_11 = Txtt106_11.Text.Trim();
			_t106.t106_77 = Txtt106_77.Text.Trim();
			_t106.t106_12 = Txtt106_12.Text.Trim();
			_t106.t106_78 = Txtt106_78.Text.Trim();
			_t106.t106_13 = Txtt106_13.Text.Trim();
			_t106.t106_14 = Txtt106_14.Text.Trim();
			_t106.t106_15 = Txtt106_15.Text.Trim();
			_t106.t106_16 = Txtt106_16.Text.Trim();
			_t106.t106_17 = Txtt106_17.Text.Trim();
			_t106.t106_18 = Txtt106_18.Text.Trim();
			_t106.t106_19 = Txtt106_19.Text.Trim();
			_t106.t106_79 = Txtt106_79.Text.Trim();
			_t106.t106_80 = Txtt106_80.Text.Trim();
			_t106.t106_81 = Txtt106_81.Text.Trim();
			_t106.t106_82 = Txtt106_82.Text.Trim();
			_t106.t106_83 = Txtt106_83.Text.Trim();
			_t106.t106_20 = Txtt106_20.Text.Trim();
			_t106.t106_21 = Txtt106_21.Text.Trim();
			_t106.t106_22 = Txtt106_22.Text.Trim();
			_t106.t106_23 = Txtt106_23.Text.Trim();
			_t106.t106_24 = Txtt106_24.Text.Trim();
			_t106.t106_25 = Txtt106_25.Text.Trim();
			_t106.t106_26 = Txtt106_26.Text.Trim();
			_t106.t106_27 = Txtt106_27.Text.Trim();
			_t106.t106_28 = Txtt106_28.Text.Trim();
			_t106.t106_29 = Txtt106_29.Text.Trim();
			_t106.t106_30 = Txtt106_30.Text.Trim();
			_t106.t106_31 = Txtt106_31.Text.Trim();
			_t106.t106_32 = Txtt106_32.Text.Trim();
			_t106.collection_time = Txtcollection_time.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_t106(_t106);
            else
                isok = mgr.Add_t106(_t106);
            if (isok)
            {
                t106_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("t106中执行了保存（插入或修改），并成功");
                t106_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}